package cn.xianshu.user.controller;

import cn.xianshu.basic.exception.BasicException;
import cn.xianshu.basic.util.AxiosResult;
import cn.xianshu.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;



    // 一定情况下MAP可以代替类使用
    @PostMapping("/smsCode")
    public AxiosResult sendSmsCode(@RequestBody Map<String, String> params){
        try {
            verifyCodeService.sendSmsCode(params);
            return AxiosResult.me();
        } catch (BasicException e) {
            e.printStackTrace();
            return AxiosResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            return AxiosResult.me().setMessage("系统繁忙!");
        }
    }
}
